package com.palm.hubo2o.util;

import android.os.CountDownTimer;
import android.widget.Button;

import com.palm.palmutils.StringUtils;

import java.util.Locale;

/**
 * Created by wongqi on 16/6/20.
 */
public class CountDownUtils {

    public static CountDownTimer countDownButton(final Button button, int seconds, final String finish) {
        button.setEnabled(false);
        return new CountDownTimer(seconds * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                button.setText(String.format(Locale.getDefault(), "剩余%d秒", (int) millisUntilFinished / 1000));
            }

            @Override
            public void onFinish() {
                if (!StringUtils.isEmpty(finish))
                    button.setText(finish);
                button.setEnabled(true);
            }
        }.start();
    }
}
